package filtersoter

import (
	"iptv_server/v3/v2_src/utils/common"
)

func NewFilter() common.Filter {
	// o := orderedmap.New[struct{}]()
	return &filter{
		store: make(map[string]struct{}),
	}
}

type filter struct {
	// store *orderedmap.Orderedmap[struct{}]
	store map[string]struct{}
}

func (f *filter) Contains(key string) bool {
	// if _, ok := f.store.Get(key); ok {
	if _, ok := f.store[key]; ok {
		return true
	}
	return false
}

func (f *filter) Size() int {
	return len(f.store)
}

func (f *filter) Keys() []string {
	keys := make([]string, 0, len(f.store))
	for k := range f.store {
		keys = append(keys, k)
	}

	return keys
}

func (f *filter) Put(key string) {
	if len(key) == 0 {
		return
	}
	if f.Contains(key) {
		return
	}
	f.store[key] = struct{}{}
}
